package com.stu.ssm_02.controller;

import com.stu.ssm_02.exception.BusinessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import javax.servlet.http.HttpServletRequest;

/**
 * ClassName: ExceptionController
 * Package: com.stu.ssm_02.controller
 * Description: @Version 1.0
 */
//全局异常处理
@ControllerAdvice
public class ExceptionController {
    @ExceptionHandler(value = {BusinessException.class})
    public String handlerException(BusinessException e, HttpServletRequest request) {
        // 需要手动设置错误信息到页面
        request.setAttribute("errorStr", e.getMsg());
        return "error";
    }
}
